package cn.com.open.ms.ecgpaasdatarest.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

public class Md5 {

    private static final Logger LOG = LoggerFactory.getLogger(IpUtil.class);

    private Md5() {}

    public static String md5(String str) {
        try{
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes(StandardCharsets.UTF_8));
            byte[] b = md.digest();
            int i;
            StringBuilder buf = new StringBuilder("");
            for (byte aB : b) {
                i = aB;
                if (i < 0) {
                    i += 256;
                }
                if (i < 16) {
                    buf.append("0");
                }
                buf.append(Integer.toHexString(i));
            }
            return buf.toString();
        }catch(Exception e){
            LOG.error(e.getMessage(), e);
            return "false";
        }
    }

}